<?php 
class category_show extends MX_Controller{
	//paging
	public $page=0;
	public $limit=10;
	
	public function index($category_id){

		//set session region
		$this->load->library('session');
		$this->session->set_userdata('category_id',$category_id);

		$chercher_annonce=$this->load->Module('annonce/chercher');
		$chercher_annonce->load_session();
		$chercher_annonce->rechercher=$chercher_annonce->codePostal='';
		$chercher_annonce->set_session(array('search'=>'','search_cp'=>''));
		$chercher_annonce->category=$category_id;
		$chercher_annonce->page=$this->page;
		$ids_anonnces=$chercher_annonce->get_list_annonces();
		$paging=$chercher_annonce->paging;
		
		
		
		
		$message_tous =$chercher_annonce->nb;
		$message_particuliers=$chercher_annonce->nb_particuliers;
		$message_professionnels =$chercher_annonce->nb_professionnels;
		$annonces=array();
		$product=$this->load->Module('product/show');
		if(!empty($ids_anonnces))
			foreach ($ids_anonnces as $id_annonce){
				$annonces[$id_annonce]=$product->get_info($id_annonce);
			}
			
			
		//list tous annonce payant
		$TopAnnonces=array();
		$limit=4;
		$annoncesList=$this->model()->get_TopAnnonce($category_id,$limit);
		if(count($annoncesList))
			foreach ($annoncesList as $id_annonce){
				$TopAnnonces[$id_annonce]=$product->get_info($id_annonce);
			} 

		$category= $this->load->module('category/index');
		$title=$category->get_name_category($category_id);
		$description=$category->get_description_category($category_id);
		$keywords=implode(',',$this->model()->get_keywords($category_id));
		$message_tous=' annonces';
		$message_particuilers=' annonces' ;
		$message_professionnels=' annonces';
		
		$modal=$list_departement='';
		
		if($this->model()->is_rencontres($category_id)) $modal=1;
		
		$data=array(
				'title'=>$title,
				'description'=>$description,
				'keywords'=>$keywords,
				'paging'=>$paging,
				'nb'=>$chercher_annonce->nb,
				'nb_particulier'=>$chercher_annonce->nb_particuliers,
				'nb_professionnells'=>$chercher_annonce->nb_professionnels,
				'message_tous'=>$message_tous,
				'message_particuilers'=>$message_particuilers ,
				'message_professionnels'=>$message_professionnels,
				'TopAnnonces'=>$TopAnnonces,
				'modal'=>$modal,
				'annonces'=>$annonces
		);
		$setting=$this->load->Module('setting/data');
		$data=$setting->data($data);

		$type=$this->session->userdata('type');
		if($type=='') $type='offre';
		$data['nav_class'][$type]='active';
		;
		$this->view(
				array('header',
					  'category',
					  'footer'),
				$data); // Display the page
	}

	public function page($category_id,$page=''){
		if($page=='')$page=0;
		$this->page=$page;
		self::index($category_id);
	}
	
}